<template>
	
	<view>
		
		<view style="background-color: #007AFF; height: 250rpx;width: 100%;">
			<text style="display:flex; flex-direction:row; justify-content:center; padding-top: 100rpx; color:#FFFFFF; font-size: large;">{{ resourceParam.searchPARAM.type}}</text>
		</view>
		<ad-interstitial></ad-interstitial>	
		<!-- <uni-grid :column="2" :showBorder="false" :square="false">
			<uni-grid-item v-for="(item,index) in resourceList" :key="index" @click="clickResource(item)">
				
				<uni-card is-full="true" @click="clickResource(item)" style="padding: 15rpx;">
					<template v-slot:cover>
							<image :src="item.imgFile" :mode="scaleToFill" @click="clickResource(item)"  style="height: 200upx; width: 100%;" ></image>
					</template>
					<uni-row >
						<uni-col :span="14">
							<text style="font-size: 28rpx; font-weight: bold; color: #555555">{{item.name.substr(0,5)}}</text>
						</uni-col>
						<uni-col :span="10">
							<text style="font-size: 12rpx;  color: #A5A4A4;">{{item.updateTime}}</text>
						</uni-col>
						
					</uni-row>
					<uni-row >
						<uni-col :span="24">
							<text style="font-size: 25rpx;color: #555555">{{item.introduce.substr(0,9)+"..."}}</text>
						</uni-col>
					</uni-row>
				</uni-card>
			</uni-grid-item>
		</uni-grid> -->
		<uni-card is-full="true" v-for="(item,index) in resourceList" :key="index" @click="clickResource(item)" style="padding: 77rpx;">
			<template v-slot:cover>
					<image :src="item.imgFile" :mode="scaleToFill" @click="clickResource(item)"  style="height: 330upx; width: 100%;" ></image>
			</template>
			<uni-row >
				<uni-col :span="18">
					<text style="font-size: 35rpx; font-weight: bold; color: #555555">{{item.name}}</text>
				</uni-col>
				<uni-col :span="6">
						<uni-tag type="warning" :text="item.type"></uni-tag>
				</uni-col>
			</uni-row>
			<uni-row >
				<uni-col :span="20">
					<text style="font-size: 25rpx;color: #555555">{{item.introduce.substr(0,20)+"..."}}</text>
				</uni-col>
				<uni-col :span="4">
						<text style="font-size: 20rpx; font-weight: 450; margin-top: 50upx; color: #555555;">{{item.updateTime}}</text>
				</uni-col>
			</uni-row>
		</uni-card>
		
		<view v-if="loading">
			<howe-loading></howe-loading>
		</view>
	</view>
</template>

<script>
	import Utils from '../../Utils.js'
	
	export default {
		data() {
			return {
				loading: true,
				resourceList: [],
				resourceParam: {
					order: "desc",
					orderBy: "update_time",
					pageNum: 1,
					pageSize: 8,
					searchPARAM: {
						id: "",
						imgFile: "",
						introduce: "",
						name: "",
						type: "",
						url: "",
						isHide: 0,
					}
				},
			}
		},
		
		onReachBottom() {
					console.log("onReach")
					this.resourceParam.pageNum=this.resourceParam.pageNum+1;
					setTimeout(() => {
						//设置延迟执行
						this.getResource()
					}, 300);
					
				},
		methods: {
			onLoad: function(e) {
				//Utils.interstitial.load('adunit-f241f3351c76873d')
				this.resourceParam.searchPARAM.type = e.type;
				uni.setNavigationBarTitle({
					title: this.resourceParam.searchPARAM.type
				})
				this.getResource()
				
				setTimeout(() => {
					//设置延迟执行
					//Utils.interstitial.show()
				}, 200);
				
				
				
				
			},
			clickResource(e) {
				uni.navigateTo({
					url: '/pages/resourcepage/resourcepage?id='+JSON.stringify(e.id)
				});
				// uni.redirectTo({
				//  	url: '/pages/resourcepage/resourcepage?id='+JSON.stringify(e.id)
				//  })
			},
			getResource(){
				this.loading=true;
				uni.request({
					url: this.$api + '/resource/page',
					header: {
						'content-type': 'application/json' //自定义请求头信息
					},
					method: 'POST',
					data: this.resourceParam,
					//请求成功后返回
					success: (res) => {
						// 请求成功之后将数据给Info
						if (res.data.code === '200') {
							
							res.data.data.records.forEach((resource) => {
								//时间截取
								resource.updateTime=resource.updateTime.slice(0,resource.updateTime.indexOf(" "));
								resource.imgFile = this.$api + '/img/' + resource.imgFile
							})
								console.log(this.resourceParam.pageNum)
								if(res.data.data.records.length < 6){
									if(res.data.data.records.length != 0){
										this.resourceList=this.resourceList.concat(res.data.data.records)
									}
									this.loading=false;
									uni.showToast({
													title: "已经到底了",
													icon:'none',
													duration:850
												});
								}else{
									this.resourceList=this.resourceList.concat(res.data.data.records)
								}
								
								

								
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "请求错误:"+res.errMsg,
							icon: 'none',
							duration: 850
						});
					}
				});
			}
		}
	}
</script>

<style>

</style>
